<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>广告倒计时<span>18S</span>秒</div>
    <script>
        //通过定时器 延时执行任务setTimeout一次,setInterval周期执行
        console.log("start");
        let firstAlarm = setTimeout(function(){
            console.log("我将会在5秒后出现");
        },5000);
        clearTimeout(firstAlarm);
        console.log("end");
        

        //倒计时
        let num = Number.parseInt(document.querySelector("span").innerHTML);//全局变量
        let broadAlarm = 0;//定义一个变量建议初始化  ,   广告计时器的句柄，用于销毁该计时器
        function doWrok(){
            document.querySelector("div").innerHTML = "welcome";
            clearInterval(broadAlarm);
        }
        setTimeout(doWrok,num*1000);//命名函数

        
        broadAlarm = setInterval(function(){
            document.querySelector("span").innerHTML = --num;
        },1000);
    </script>
</body>
</html>